import service from '@/api/request'
import config from './config'
import type { FormData, ResPageList, SearchParams } from './page.type'

const PageApi = config.api
/**
 * 图片上传响应接口
 */

const pageApi = {
  // 获取列表
  getList: (page: number, size: number, params?: SearchParams) =>
    service.get<ResPageList>(PageApi.GET_URL, { params: { current: page, size, ...params } }),
  // 新增
  create: (data: FormData) => service.post(PageApi.CREATE_URL, data),
  // 修改
  update: (data: FormData) => {
    // 构建发送数据，过滤掉不应该发送的字段
    const id = data.id as string
    delete data.id
    delete data.createdAt
    delete data.updatedAt
    return service.put(PageApi.UPDATE_URL + `/${id}`, data)
  },
  // 删除
  delete: (id: string) => service.delete(PageApi.DELETE_URL + `/${id}`),
  // 批量删除品牌
  batchDelete: (ids: string[]) => service.delete(PageApi.BATCH_DELETE_URL, { data: ids }),
}

export default pageApi
